package com.itc.bi.controller;

import com.itc.bi.entity.DataSetColumnEntity;
import com.itc.bi.entity.DirectDataSetEntity;
import com.itc.bi.query.DataSetColumnQuery;
import com.itc.bi.service.DataSetColumnService;
import com.itc.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(value = "数据集表头",tags = "数据集表头")
@RequestMapping("/dataSetColumn")
public class DataSetColumnController {

    @Autowired
    DataSetColumnService service;

    @GetMapping("/get/{id}")
    @ApiOperation(value = "根据ID获取数据")
    public R<DataSetColumnEntity> get(@PathVariable("id") Long id){
        DataSetColumnEntity entity = service.getById(id);
        if(null == entity){
            return R.fail("获取数据失败，记录不存在");
        }
        return R.ok(entity);
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取列表")
    public R<List<DataSetColumnEntity>> list(@RequestBody DataSetColumnQuery query){
        return R.ok(service.list(query));
    }

    @PostMapping("/save")
    @ApiOperation(value = "修改")
    public R save(@Valid @RequestBody DataSetColumnEntity entity){
        return R.ok(service.updateById(entity));
    }

    @PostMapping("/saveBatch")
    @ApiOperation(value = "批量修改")
    public R save(@RequestBody List<DataSetColumnEntity> list){
        service.batch(list);
        return R.ok();
    }

}
